package com.appcheck.recording.action.impl;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.appcheck.recording.action.AbstractAction;
import com.appcheck.recording.action.ActionConvert;
import com.appcheck.recording.action.DefaultAction;
import com.appcheck.recording.handler.AbstractActionHandler;
import com.appcheck.recording.model.IdNamePair;
import com.appcheck.recording.plugin.AbstractActionConverter;

public final class ClickAction extends DefaultAction implements AbstractAction, ActionConvert {

	private int viewType;
	private String text;
	private boolean longClick;
	


	public final String toString(){
	  JSONObject localJSONObject = new JSONObject();
	  try{
	    localJSONObject.put("class", "ClickAction");
	    localJSONObject.put("viewType", this.viewType);
	    localJSONObject.put("id", this.resourceId);
	    localJSONObject.put("name", this.resourceName);
	    localJSONObject.put("text", this.text);
	    localJSONObject.put("index", this.index);
	    localJSONObject.put("longClick", this.longClick);
	    if(preViewArray != null){
	    	JSONArray jsonArray = new JSONArray();
		    for(IdNamePair pair : preViewArray){
		    	JSONObject idNamePair = new JSONObject();
		    	idNamePair.put("resourceName", pair.getResourceName());
		    	idNamePair.put("resourceId", pair.getResourceId());
		    	jsonArray.put(idNamePair);
		    }
		    localJSONObject.put("preViewList", jsonArray);
	    }

	   
	  }catch (JSONException localJSONException) {}
	    return localJSONObject.toString();
	}


	public ClickAction() {
		super();
	}


	public ClickAction(int viewType, int id, String name, boolean longClick) {
		super();
		this.viewType = viewType;
		this.text = text;
		this.resourceId = id;
		this.resourceName = name;
		this.longClick = longClick;
	}


	public final String getText() {
		return text;
	}

	public final void setViewType(int viewType) {
		this.viewType = viewType;
	}

	public final void setText(String text) {
		this.text = text;
	}

	public final void setLongClick(boolean longClick) {
		this.longClick = longClick;
	}

	@Override
	public boolean handle(AbstractActionHandler param) {
		return param.visit(this);
	}

	@Override
	public void toTestCode(AbstractActionConverter actionConverter) {
		actionConverter.convert(this);
	}

}
